import { createVNode, render } from 'vue'
import component from './Tip.vue'

function tip(str, type, withIcon = false) {

  const div = document.createElement('div')
  document.body.appendChild(div)
  const vNode = createVNode(component, { type, str, withIcon })
  render(vNode, div)

  const timer = setTimeout(() => {
    render(null, div)
    clearTimeout(timer)
  }, 3500)
}

export default {
  warn: (str, withIcon = false) => tip(str, 'warn', withIcon),
  success: (str, withIcon = false) => tip(str, 'success', withIcon),
  error: (str, withIcon = false) => tip(str, 'error', withIcon)
}